package com.chuanke.ckfamily.service.common.impl;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import java.util.Set;


/**
 * 业务层缓存实现，替代之前的memcachedService Date: 2016年11月6日 上午10:50:11 <br/>
 * 
 * @author yc
 * @version
 * @since JDK 1.7
 * @see
 */
@SuppressWarnings("rawtypes")
@Component
public class RedisCacheServiceImpl extends AbstractRedisCacheService {
	
	private static final Logger logger = LoggerFactory.getLogger(RedisCacheServiceImpl.class);

	private static final long serialVersionUID = -7981677722291581141L;

	@SuppressWarnings("unchecked")
	@Override
	@Deprecated
	public void deleteByPrex(String prex) {
		long start = System.currentTimeMillis();
		Set<String> keys = redisTemplate.keys(prex + "*");
		redisTemplate.delete(keys);
		long end = System.currentTimeMillis();
		long ms = end - start;
		if (ms > 100) {
			logger.warn("CacheService.deleteByPrex执行时间超过" + ms + "ms");
		}
	}

	/**
	 * like查询条数
	 * 
	 * @param prex
	 * @return
	 */
	public Integer getByPrexSize(String prex) {
		long start = System.currentTimeMillis();
		Set<String> keys = redisTemplate.keys(prex + "*");
		if (null == keys) {
			return 0;
		}
		int size = keys.size();
		long end = System.currentTimeMillis();
		long ms = end - start;
		if (ms > 100) {
			logger.warn("CacheService.getByPrexSize执行时间超过" + ms + "ms");
		}
		return size;
	}

	/**
	 *
	 *
	 * @param prex
	 * @return
	 */
	public Set<String> getKeysByPrex(String prex) {
		return redisTemplate.keys(prex + "*");
	}
}
